package com.kaikai.edu.controller;


import com.kaikai.commonutils.R;
import com.kaikai.edu.entity.EduSubject;
import com.kaikai.edu.entity.subject.OneSubject;
import com.kaikai.edu.service.EduSubjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author yujiankai
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    EduSubjectService subjectService;

    //添加课程分类
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        //获取上传excel文件,添加分类信息
        subjectService.importSubjectData(file);
        return R.ok();
    }

    /**
     * 得到所有分类
     * @return
     */
    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<OneSubject> allList=subjectService.getOneTwoSubject();
        return R.ok().data("list",allList);
    }

    /**
     * @param id
     * @return com.kaikai.commonutils.R
     * @Author yujiankai
     * @Description 根据id删除课程分类
     * @date 2022/1/26 15:19
     */
    @GetMapping("deleteSubjectById/{id}")
    public R deleteSubjectById(@PathVariable String id){
        return subjectService.deleteSubjectById(id);
    }

    /**
     * @param subject
     * @return com.kaikai.commonutils.R
     * @Author yujiankai
     * @Description 更新课程信息
     * @date 2022/1/26 15:31
     */
    @ApiOperation("更新课程信息")
    @PostMapping("updateSubject")
    public R updateSubject(@RequestBody EduSubject subject){
        return subjectService.updateSubject(subject);
    }

    /**
     * @param subject
     * @return com.kaikai.commonutils.R
     * @Author yujiankai
     * @Description 添加课程信息
     * @date 2022/1/26 15:32
     */
    @PostMapping("createSubject")
    public R createSubject(@RequestBody EduSubject subject){
        return subjectService.createSubject(subject);
    }

}

